﻿using Dapper;
using PoemGame.ComputerAnswer.Shared;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PoemGame.ComputerAnswer.Db
{
    public class ComputerAnswerFeihualing : IComputerAnswer
    {
        private readonly IDbConnection conn;
        public ComputerAnswerFeihualing(IDbConnection _conn)
        {
            conn = _conn;
        }
        public string Answer(string gamecontext, string lastanswer)
        {
            var rows = conn.Query<PoemLine>("select * from PoemLine where LineContent like '%" + gamecontext + "%'").ToList(); 
            if (rows.Any())
            {
                var rnd = new Random();
                var idx = rnd.Next(rows.Count());
                return rows[idx].LineContent;

            }
            return "";
        }
    }
}
